#include "gamehall.h"
#include "ui_gamehall.h"
#include <QPainter>
#include <QPixmap>
#include <QIcon>
#include <QPushButton>
#include <QFont>
#include <gameselect.h>
#include <QSound>

GameHall::GameHall(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::GameHall)
{
    ui->setupUi(this);

    //设置窗口大小
    this->setFixedSize(1000,800);

    //设置窗口图标
    QIcon icon(":res/ico.png");
    this->setWindowIcon(icon);

    //设置窗口标题
    this->setWindowTitle("贪吃蛇游戏");


    //设置按钮
    QPushButton* startBtn = new QPushButton(this);
    startBtn->move(430,530);
    startBtn->setText("开始游戏");
    QFont font("华文行楷",24);
    startBtn->setFont(font);
    startBtn->setStyleSheet("QPushButton:{border: 2px solid #8f8f91; border-radius: 15px}");

    //第二个游戏选择窗口
    GameSelect* gameselect = new GameSelect;
    //通过按钮跳转到第二个游戏窗口
    connect(startBtn,&QPushButton::clicked,this,[=](){
        this->close();
        QSound::play(":res/clicked.wav");
        gameselect->setGeometry(this->geometry());
        gameselect->show();
    });
}

GameHall::~GameHall()
{
    delete ui;
}

void GameHall::paintEvent(QPaintEvent *event)
{
    //实例化画家对象
    QPainter painter(this);

    //实例化绘图设备
    QPixmap pix(":res/game_hall.png");

    //绘画
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

